package com.xq.controller;

import com.xq.apis.SysDictApis;
import com.xq.constants.ErrorCodeConstants;
import com.xq.dto.SysDict.*;
import com.xq.service.ISysDictDataService;
import com.xq.service.ISysDictTypeService;
import com.xq.vo.JsonVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "字典管理")
@RestController
@RequestMapping("/sys-dict-manage")
public class SysDictManageController implements SysDictApis {

    @Autowired
    private ISysDictTypeService sysDictTypeService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    @ApiOperation("增加字典类型")
    @PostMapping("/insert-dict-type")
    @Override
    public JsonVO<String> insertDict(SysDictInsertDTO sysDictInsertDTO) {
        sysDictTypeService.insertDict(sysDictInsertDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("删除字典类型")
    @DeleteMapping("/delete-dict-type")
    @Override
    public JsonVO<String> deleteDict(@RequestParam String dictCode) {
        sysDictTypeService.deleteDict(dictCode);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("/更新字典类型")
    @PutMapping("/update-dict-type")
    @Override
    public JsonVO<String> updateDict(SysDictUpdateDTO sysDictUpdateDTO) {
        sysDictTypeService.updateDict(sysDictUpdateDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("查出字典类型")
    @GetMapping("/list-dict-type")
    @Override
    public JsonVO<List<SysDictListDTO>> listDict(@RequestParam String dictCode) {
        List<SysDictListDTO> sysDictListDTOS = sysDictTypeService.listDict(dictCode);
        return JsonVO.success(sysDictListDTOS);
    }

    @ApiOperation("插入字典数据")
    @PostMapping("/insert-dict-data")
    @Override
    public JsonVO<String> insertDictData(SysDictDataInsertDTO sysDictDataInsertDTO) {
        sysDictDataService.insertDictData(sysDictDataInsertDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("删除字典数据")
    @DeleteMapping("/delete-dict-data")
    @Override
    public JsonVO<String> deleteDictData(@RequestParam String dictCode) {
        sysDictDataService.deleteDictData(dictCode);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("更新字典数据")
    @PutMapping("/update-dict-data")
    @Override
    public JsonVO<String> updateDictData(SysDictDataUpdateDTO sysDictDataUpdateDTO) {
        sysDictDataService.updateDictData(sysDictDataUpdateDTO);
        return JsonVO.success(ErrorCodeConstants.SUCCESS);
    }

    @ApiOperation("查出字典数据")
    @GetMapping("/list-dict-data")
    @Override
    public JsonVO<List<SysDictDataListDTO>> listDictData(@RequestParam String dictCode) {
        List<SysDictDataListDTO> sysDictDataListDTOS = sysDictDataService.listDictData(dictCode);
        return JsonVO.success(sysDictDataListDTOS);
    }

}
